xlv.obj.radioGroup={
	extend:function(){
	},
	implement:function(){
		this.implement('xlv.imp.mvc');
		this.implement('xlv.imp.editor');
	},
	create:function(tag){
		var div=document.createElement((tag||'div'));
		div.setAttribute('xlvobject','xlv.obj.radioGroup');
		return div;			
	},
	properties:{
		dmName:null,
		dmPath:null,
		groupName:null,
		radios:null
	},
	method:{
		construct:function(){
			var v=this.$V;
			var gname=(this.$P.groupName)?this.$P.groupName:''+(new Date().getTime());
			v.radios=xlv.util.children(this,{tag:'input',type:'radio'});
			if(v.radios.length>0) {
				for(var i=0;i<v.radios.length;++i)v.radios[i].name=gname;
				return;
			}
			if(!this.$P.radios)	this.$P.radios=[{text:'radio',value:'test',br:false,title:null}];
			v.editor=this;
			//
			var html='';//IE cannot use createElement
			for(var i=0;i<this.$P.radios.length;++i){
				var idpatch=xlv.util.autoIncInteger();
				var text=(this.$P.radios[i].text||'');
				var title=(this.$P.radios[i].title||'');
				if(!this.$P.radios[i].htmlText) text=text.escapeHTML();
				html+='<input name="'+gname+'" type="radio" id="'+gname+'_'+idpatch+'"></input>';
				html+='<label for="'+gname+'_'+idpatch+'" title="'+title+'" >'+text+'</label>'; 
				if(this.$P.radios[i].br)html+='<br/>';
			}
			this.innerHTML=html;
			v.radios=xlv.util.children(this,{tag:'input',type:'radio'});
			for(var i=0;i<v.radios.length;++i){
				if(this.$P.radios[i]) v.radios[i].value=this.$P.radios[i].value;
				this.styleFor(v.radios[i],i);
			}
		},
		initial:function(){
			if(Prototype.Browser.IE) {
				for(var i=0;i<this.$V.radios.length;++i) this.addEventHandler('click', '_change',this.$V.radios[i]);
			}else this.addEventHandler('change', '_change',this);
		},
		dispose:function(){
		},
		styleFor:function(radio,index){
		},
		_change:function(event){
			var dm=this.mvc_getModel();
			if(dm)this.mvc_valueToModel(this.mvc_valueFromView(),dm);
		},
		isChecked:function(value,index){
			return (value==this.$V.radios[index].value);
		},
		/**mvc imp*/
		mvc_valueFromModel:function(dm){
			return this.mvc_isModel(dm) ? dm.getValue(this.$P.dmPath) : null;
		},
		mvc_valueToModel:function(value,dm){
			if(this.mvc_isModel(dm)) dm.setValue(value,this.$P.dmPath);
		},
		mvc_beforeModelChanged:function(model,notify,memo){
			if(this.mvc_isModel(model)&& notify=='cursorMove'&& this.editor_editing())
				this._editor_endEdit(true);
		},
		mvc_valueFromView:function(){
			var v=this.$V;
			for(var i=0;i<v.radios.length;++i){
				if(v.radios[i].checked) return v.radios[i].value;
			}
			return '';
		},
		mvc_valueToView:function(value){
			var v=this.$V;
			for(var i=0;i<v.radios.length;++i){
				v.radios[i].checked=this.isChecked(value,i);
			}
		},
		/**editor imp*/
		editor_blur:function(){
			var v=this.$V;
			for(var i=0;i<v.radios.length;++i){
				v.radios[i].blur();
			}
		},
		editor_valueToEditor:function(value){
			this.mvc_valueToView(value);
		},
		editor_valueFromEditor:function(){
			return this.mvc_valueFromView(); 
		}
	}
};
